package com.lmx.repoDomain.tmodel;

import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ForeignKey;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import com.lmx.repoDomain.tmodel.business.User;

import io.katharsis.resource.annotations.JsonApiIncludeByDefault;
import io.katharsis.resource.annotations.JsonApiResource;
import io.katharsis.resource.annotations.JsonApiToMany;
import io.katharsis.resource.annotations.JsonApiToOne;


/**
 * 床位表
 */
@JsonApiResource(type = "bed")
@Table(name = "tnb_bed")
@Entity
//@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Bed extends BaseEntity {

	private String remark;// 备注

	private String name;// 房屋名称

	private String price;// 价格

	private Dicttype status;// 状态 已分配 未分配

	private Integer createDateTime;// 创建时间

	private User createUser;

	private Integer lastUpdateDateTime;// 更新时间

	private String buttonID;// 小米按键id

	private Room room;// 所属房屋

	private Dicttype bedType;// 床位类型

	private User lastUpdateUser;// 更新操作者userid

	private Dicttype nursingType;// 护理类型

	private List<BedNurseGroup> groups;// 所属护理组

	private Customer customer;

	private Device button;// 华米按键

	@JsonApiToOne
	@JsonApiIncludeByDefault
	@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.REFRESH)
	@Fetch(FetchMode.JOIN)
	@JoinColumn(name = "button_id", nullable = true, foreignKey = @ForeignKey(name = "null"))
	public Device getButton() {
		return button;
	}

	public void setButton(Device button) {
		this.button = button;
	}

	@Transient
	public Customer getCustomer() {
		return customer;
	}

	public void setCustomer(Customer customer) {
		this.customer = customer;
	}

	@JsonApiToMany
	@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
	@JoinTable(name = "tnb_bed_nursegroup", joinColumns = {
			@JoinColumn(name = "bed_id", nullable = false, updatable = false, foreignKey = @ForeignKey(name = "null")) }, inverseJoinColumns = {
					@JoinColumn(name = "group_id", nullable = false, updatable = false, foreignKey = @ForeignKey(name = "null")) })
	public List<BedNurseGroup> getGroups() {
		return groups;
	}

	public void setGroups(List<BedNurseGroup> groups) {
		this.groups = groups;
	}

	public Bed() {
	}

	@Column(name = "name")
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column(name = "price")
	public String getPrice() {
		return price;
	}

	public void setPrice(String price) {
		this.price = price;
	}

	@JsonApiToOne
	@JsonApiIncludeByDefault
	@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.REFRESH)
	@Fetch(FetchMode.JOIN)
	@JoinColumn(name = "status_id", nullable = true, foreignKey = @ForeignKey(name = "null"))
	public Dicttype getStatus() {
		return status;
	}

	public void setStatus(Dicttype status) {
		this.status = status;
	}

	@Column(name = "createDateTime")
	public Integer getCreateDateTime() {
		return createDateTime;
	}

	public void setCreateDateTime(Integer createDateTime) {
		this.createDateTime = createDateTime;
	}

	@JsonApiToOne
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "createUser_id", nullable = true, foreignKey = @ForeignKey(name = "null"))
	public User getCreateUser() {
		return createUser;
	}

	public void setCreateUser(User createUser) {
		this.createUser = createUser;
	}

	@Column(name = "lastUpdateDateTime")
	public Integer getLastUpdateDateTime() {
		return lastUpdateDateTime;
	}

	public void setLastUpdateDateTime(Integer lastUpdateDateTime) {
		this.lastUpdateDateTime = lastUpdateDateTime;
	}

	@Column(name = "buttonID")
	public String getButtonID() {
		return buttonID;
	}

	public void setButtonID(String buttonID) {
		this.buttonID = buttonID;
	}

	@JsonApiToOne
	@JsonApiIncludeByDefault
	@Fetch(FetchMode.JOIN)
	@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.REFRESH)
	@JoinColumn(name = "bedtype_id", nullable = true, foreignKey = @ForeignKey(name = "null"))
	public Dicttype getBedType() {
		return bedType;
	}

	public void setBedType(Dicttype bedType) {
		this.bedType = bedType;
	}

	@JsonApiToOne
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "lastUpdateUser_ID", nullable = true, foreignKey = @ForeignKey(name = "null"))
	// @JsonBackReference
	public User getLastUpdateUser() {
		return lastUpdateUser;
	}

	public void setLastUpdateUser(User lastUpdateUser) {
		this.lastUpdateUser = lastUpdateUser;
	}

	@JsonApiToOne
	@JsonApiIncludeByDefault
	@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.REFRESH)
	@JoinColumn(name = "nursingtype_id", nullable = true, foreignKey = @ForeignKey(name = "null"))
	public Dicttype getNursingType() {
		return nursingType;
	}

	public void setNursingType(Dicttype nursingType) {
		this.nursingType = nursingType;
	}

	@JsonApiToOne
	@JsonApiIncludeByDefault
	@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.REFRESH)
	@Fetch(FetchMode.JOIN)
	@JoinColumn(name = "room_id", nullable = true, foreignKey = @ForeignKey(name = "null"))
	public Room getRoom() {
		return room;
	}

	public void setRoom(Room room) {
		this.room = room;
	}

	// @JsonApiToMany
	// @OneToMany(mappedBy = "parent")
	// @JsonManagedReference
	// public List<Bed> getChildren() {
	// return children;
	// }
	//
	// public void setChildren(List<Bed> children) {
	// this.children = children;
	// }

	@Column(name = "remark")
	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}
}
